package controller;

import com.alibaba.fastjson.JSON;
import entity.Dorm_buildings;
import service.DormbuildingsService;
import service.impl.DormbuildingsServicelmpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/Dorm_buildingsController")
public class Dorm_buildingsController extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession(true);
        String op = req.getParameter("op");
        PrintWriter out=resp.getWriter();
        if(op.equals("cx")){
            DormbuildingsService dor=new DormbuildingsServicelmpl();
            List<Dorm_buildings> list=null;
            try {
                list=dor.cx();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            out.write(JSON.toJSONString(list));
        }
    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
